<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH 优先级队列编辑</title>
    <meta name="keywords" content="ZDH 优先级队列编辑">
    <meta name="description" content="ZDH 优先级队列编辑">

    <link rel="shortcut icon" href="img/favicon.ico">
    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/switchery/switchery.css" rel="stylesheet">


</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row">

            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>修改优先级</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                                <i class="fa fa-eye"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="javascript:void(0);" onclick="getResourceDesc()">功能说明</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="signupForm">

                            <div class="form-group">
                                <label class="col-sm-3 control-label">队列名：</label>
                                <div class="col-sm-8">
                                    <input id="queue_name" name="queue_name" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">内容：</label>
                                <div class="col-sm-8">
                                    <input id="msg" name="msg" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">优先级：</label>
                                <div class="col-sm-8">
                                    <input id="priority" name="priority" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="button" id="btn_up" οnsubmit='return false'>保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <script src="js/zdh_common.js"></script>
    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="js/content.js?v=1.0.0"></script>

    <!-- jQuery Validation plugin javascript-->
    <script src="js/plugins/validate/jquery.validate.min.js"></script>
    <script src="js/plugins/validate/messages_zh.min.js"></script>

    <!-- Switchery -->
    <script src="js/plugins/switchery/switchery.js"></script>

    <!-- layer javascript -->
    <script src="js/plugins/layer/layer.min.js"></script>

    <script src="js/plugins/chosen/chosen.jquery.js"></script>

    <script>

        (function(document, window, $) {


            var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
            var params = url.substr(1);//去掉问号
            var pa = params.split("&");
            var s = new Object();//定义一个全局变量-存储任务ID
            for (var i = 0; i < pa.length; i++) {
                s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
            }


            if(s.queue_name != '-1'){
                build(s.queue_name, s.msg, s.priority);
                $('#btn_up').click(function () {
                    $.ajax({
                        type: 'POST',
                        url: server_context+"/zdh_queue_update",
                        dataType: 'json',
                        data: $("#signupForm").serialize()+"&old_priority="+s.priority,
                        //发送数据前
                        beforeSend: function () {
                            // 禁用按钮防止重复提交
                            $("#btn_up").attr({disabled: "disabled"});
                        },
                        //成功返回
                        success: function (data) {
                            $("#btn_up").removeAttr('disabled');
                            if(data.code == "200"){
                                layer.msg('更新成功', {
                                    time: 5000, //20s后自动关闭
                                    btn: ['更新成功,5s后自动关闭']
                                },function () {
                                    $("#etl_task_text",window.parent.document).val(JSON.stringify(data.result));
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    console.info("index: "+index);
                                    parent.layer.close(index); //再执行关闭
                                    //parent.layer.closeAll();
                                });

                            }else{
                                layer.msg('更新失败,'+data.result, {
                                    time: 5000, //20s后自动关闭
                                    btn: ['更新失败,5s后自动关闭']
                                },function () {

                                });
                            }
                        },
                        //处理完成
                        complete: function () {
                            $("#btn_up").removeAttr('disabled');
                            console.info("complete")
                        },
                        //报错
                        error: function (data) {
                            $("#btn_up").removeAttr('disabled');
                            layer.msg(data.responseText);
                            console.info("error: " + data.responseText);
                        }
                    });
                });
            }else{
                $('#btn_up').click(function () {
                    $.ajax({
                        type: 'POST',
                        url: server_context+"/zdh_queue_add",
                        dataType: 'json',
                        data: $("#signupForm").serialize(),
                        //发送数据前
                        beforeSend: function () {
                            // 禁用按钮防止重复提交
                            $("#btn_up").attr({disabled: "disabled"});
                        },
                        //成功返回
                        success: function (data) {
                            $("#btn_up").removeAttr('disabled');
                            if(data.code == "200"){
                                layer.msg('新增成功')
                            }else{
                                layer.msg('更新失败')
                            }
                        },
                        //处理完成
                        complete: function () {
                            $("#btn_up").removeAttr('disabled');
                            console.info("complete")
                        },
                        //报错
                        error: function (data) {
                            $("#btn_up").removeAttr('disabled');
                            layer.msg(data.responseText);
                            console.info("error: " + data.responseText);
                        }
                    });
                });
            }

            function  build(queue_name, msg, priority) {

                $('#queue_name').val(queue_name);
                $('#queue_name').attr({ readonly: 'true' });
                $('#msg').val(msg);
                $('#msg').attr({ readonly: 'true' });
                $('#priority').val(priority);
            }

        })(document, window, jQuery);


    </script>

</body>



</html>
